﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using KVB.Common;


namespace Customer_Profile.eCard.DBDao
{
    public class CflowDao
    {
        public static bool AddCflow(string card_no,
                                    DateTime cflow_date,
                                    //string cparty_id,
                                    decimal amount,
                                    string cflow_status,
                                    string cflow_type,
                                    string remark,
                                    string deal_no)          //添加一个卡账记录
        {
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                SqlParameter[] parameters ={ new SqlParameter("@card_no ", SqlDbType.VarChar,50),
                                             new SqlParameter("@cflow_date ",SqlDbType.DateTime),
                                             //new SqlParameter("@cparty_id ",SqlDbType.VarChar,50),
                                             new SqlParameter("@amount ",SqlDbType.Decimal),
                                             new SqlParameter("@cflow_status ",SqlDbType.VarChar,20),
                                             new SqlParameter("@cflow_type ",SqlDbType.VarChar,50),
                                             new SqlParameter("@remark ",SqlDbType.NVarChar,250),
                                             new SqlParameter("@deal_no ",SqlDbType.VarChar,50)};
                parameters[0].Value = card_no;
                parameters[1].Value = cflow_date;
                //parameters[2].Value = cparty_id;
                parameters[2].Value = amount;
                parameters[3].Value = cflow_status;
                parameters[4].Value = cflow_type;
                parameters[5].Value = remark;
                parameters[6].Value = deal_no;
                DB.ExecuteNonQuery(conn, CommandType.StoredProcedure, "eCard_cflow_insert", parameters);
                return true;
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("CflowDao.AddCflow", e.Message);
                return false;
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
        }

        public static DataSet getcflows(string card_no,string deal_no)   //搜索 cflow by cardno and dealno
        {
            DataSet ds = null;
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                SqlParameter[] parameters = { 
                                                new SqlParameter("@card_no ", SqlDbType.VarChar, 50),
                                                new SqlParameter("@deal_no ", SqlDbType.VarChar, 50)
                                            };

                parameters[0].Value = card_no;
                parameters[1].Value = deal_no;
                ds = DB.ExecuteDataset(conn, CommandType.StoredProcedure, "eCard_cflow_bycardnoAnddealno", parameters);
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("CflowDao.AddCflow", e.Message);
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return ds;
        }

        public static DataSet getcflowsBycardno(string card_no)   //搜索 cflow by cardno
        {
            DataSet ds = null;
            SqlConnection conn = null;
            try
            {
                DB.Connection(ref conn);
                SqlParameter[] parameters = { 
                                                new SqlParameter("@card_no ", SqlDbType.VarChar, 50)
                                            };

                parameters[0].Value = card_no;
                ds = DB.ExecuteDataset(conn, CommandType.StoredProcedure, "eCard_cflow_bycardno", parameters);
            }
            catch (Exception e)
            {
                KVB.Common.Log.WriteDefaultLog("CflowDao.getcflows", e.Message);
            }
            finally
            {
                DB.ConnDispose(ref conn);
            }
            return ds;
        }
    }
}